package com.as3this.ui
{
	import com.as3this.core.Destination;
	import com.as3this.core.ServiceIcon;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.system.System;
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class StandardMenu extends BaseSharingMenu
	{
		public function StandardMenu(canvas:Sprite, destinations:Array, config:Object)
		{
			super(canvas, destinations, config);
		}
		
		override public function createDisplay(destinations:Array) : void
		{
			var itemY:int = 0;
		
			for (var i:uint = 0; i < destinations.length; i++)
			{
				// create a temporary container
				var tempSprite:Sprite = new Sprite();
				
				// what is the service code for this destination?
				var serviceCode	:String = destinations[i];
				
				// add the icon for this service code
				var icon:ServiceIcon = new ServiceIcon(0, 0, serviceCode);
				tempSprite.addChild(icon);
				
				// and textfield
				var tf:TextField = createField(config.labelX || ServiceIcon.DEFAULT_SIZE, config.labelY || -1, Destination.getTitle(serviceCode));
				tempSprite.addChild(tf);
				
				// now wrap into a working button
				var btn:BaseMenuItem = new BaseMenuItem(i%2 == 1?160:0, itemY, serviceCode, tempSprite);
				container.addChild(btn);
				
				if (i%2 == 1) itemY += btn.height + int(config.vPadding);
			}
		}
		
		protected function createField(x:int, y:int, txt:String) : TextField
		{
			var tf:TextField = new TextField();
			tf.x = x;
			tf.y = y;
			tf.textColor = config.static_hex || 0x000000;
			if (config.font) tf.embedFonts = true;
			tf.antiAliasType = AntiAliasType.ADVANCED;
			tf.autoSize = TextFieldAutoSize.LEFT;
					
			var fmt:TextFormat = new TextFormat();
			fmt.size = config.size || 15;
			fmt.font = config.font || "_sans";
			tf.defaultTextFormat = fmt;
					
			tf.text = txt;
					
			return tf;
		}

	}
}